define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form, ShowJumpto) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ads/gold/index' + location.search,
                    table: 'self_gold_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pageList: [10, 20, 50],
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [
                        {
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id'),
                            searchable: false
                        },
                        {
                            field: 'user_id',
                            title: __('领取用户'),
                            operate: false,
                            searchable: false,
                            formatter: function(v,r,i){
                                return r.user_info ? r.user_info.nickname : ''
                            }
                        },
                        {
                            field: 'gold_num',
                            title: '金币数量',
                            sortable: true,
                            operate: false,
                            searchable: false
                        },
                        {
                            field: 'updatetime',
                            title: __('领取时间'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});